package com.miz.bincalc;

import android.util.Log;

public class BinaryMath {
	private int first = 0, second = 0;
	private String s_first = "", s_second = ""; 
	public static final int CONVERT_FIRST = 1, CONVERT_SECOND = 2, CONVERT_BOTH = 3;
	
	public BinaryMath(int first){
		this.first = first;
	}
	
	public BinaryMath(int first, int second){
		this.first = first;
		this.second = second;
	}

	public String convertToBinary(int flag){
		boolean bool = false;
		int tmp = 0;
		switch(flag){
			case CONVERT_FIRST:
				tmp = first;
			break;
			case CONVERT_SECOND:
				tmp = second;
			break;
			case CONVERT_BOTH:
				tmp = first;
				bool = true;
			break;
		}
		
		String ret = "", num = "";
		do{
			ret += tmp + " | ";
			ret += (tmp%2 != 0 ? "1" : "0");
			num += (tmp%2 != 0 ? "1" : "0");
			tmp /= 2;
			ret += "\n";
		}while(tmp > 0);
		
		s_first = new StringBuffer(num).reverse().toString();
		ret += "\n" + s_first;
		
		if(bool)
			ret += "\n\n" + convertToBinary(CONVERT_SECOND);
		
		return ret;
	}

}
